home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dbdoc.zip / DBDOC.C < prev    next >
C/C++ Source or Header  |  1991-12-08  |  3KB  |  112 lines

  1. /**************************************/
  2. /*       dbdoc.c                      */
  3. /*   dBASE documentor                 */
  4. /*   Programmer:  Jay Parsons         */
  5. /*   Version 1.0   10/31/91           */
  6. /**************************************/
  7.  
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <dir.h>
  11. #include <dos.h>
  12.  
  13. /**************************************/
  14. /*       global declarations          */
  15. /**************************************/
  16.  
  17. char file_name[ 78 ], message[ 1024 ], tempbuff[ 128 ];
  18.  
  19. /**************************************/
  20. /*       function declarations        */
  21. /**************************************/
  22.  
  23. int main( int argc, char *argv[] );
  24. void printit( int err );
  25.  
  26. extern int memdoc(), dbfdoc(), mdxdoc(), qbedoc(), dbtdoc();
  27.  
  28. /**************************************/
  29. /*       main routine                 */
  30. /*                                    */
  31. /*  Assumes first command-line        */
  32. /*  argument is the file to document. */
  33. /*                                    */
  34. /*  If the file is not found or no    */
  35. /*  routine exists for files of that  */
  36. /*  extension type, quits with a      */
  37. /*  message.                          */
  38. /*                                    */
  39. /*  Otherwise passes the file name    */
  40. /*  to the appropriate routine for    */
  41. /*  files of that extension.          */
  42. /*                                    */
  43. /**************************************/
  44.  
  45. int main( int argc, char *argv[] )
  46. {
  47.     struct ffblk ffblk;
  48.     int err;
  49.     char *dot, extension[5];
  50.      char *ftypes = ".MEM.DBF.MDX.QBE.DBT";
  51.      int (*ext_ptr[]) () = { memdoc, dbfdoc, mdxdoc, qbedoc, dbtdoc };
  52.  
  53.     if ( argc != 2 )
  54.     {
  55.         strcpy( message, "Syntax is \"Dbdoc <filespec>\"" );
  56.         printit( 1 );
  57.         return( 0 );
  58.     }
  59.  
  60.     strcpy( file_name , strupr( argv[ 1 ] ) );
  61.     if ( ( dot = strchr( file_name, '.' ) ) == NULL )
  62.     {
  63.         strcpy( message, "File extension must be given" );
  64.         printit( 1 );
  65.         return( 0 );
  66.     }
  67.  
  68.     if ( findfirst( file_name, &ffblk, 0 ) )
  69.     {
  70.         sprintf( message, "Can't find file %s", file_name );
  71.         printit( 1 );
  72.         return( 0 );
  73.     }
  74.  
  75.     strupr( strcpy( extension, dot ) );
  76.     if ( ( dot = strstr( ftypes, extension ) ) == NULL )
  77.     {
  78.         sprintf( message, "File of extension type %s not supported", extension );
  79.         printit( 1 );
  80.         return( 0 );
  81.     }
  82.  
  83.     err = ( *ext_ptr[ ( dot - ftypes ) / 4 ] ) ( file_name ) ;
  84.  
  85.     if( ! err )
  86.         putchar('\n');
  87.     return err;
  88. }
  89.  
  90. /************************************/
  91. /*    void printit( int err )       */
  92. /*                                  */
  93. /*   prints "message" to stdout,    */
  94. /*   or to stderr if err, and \n.   */
  95. /*                                  */
  96. /*   Minimal sophistication, for    */
  97. /*   test purposes only.            */
  98. /************************************/
  99.  
  100. void printit( int err )
  101. {
  102.     if ( err )
  103.     {
  104.         fputs( message, stderr );
  105.         fputc( '\n', stderr );
  106.     }
  107.     else
  108.         if ( *message != '\0' )
  109.             puts( message );
  110. }
  111. /*        EOF        */
  112.